package com.example.qxfw.rcyw.task;

import com.example.qxfw.common.entity.yj.ThunderMoniInfo;
import com.example.qxfw.rcyw.mapper.ThunderMoniInfoMapper;
import com.example.qxfw.rcyw.service.ThunderMoniInfoService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: xwx
 * @description: 用来监控雷电信息
 * @date: 2024/5/9
 * @version: 1.0
 */
@Component
@EnableScheduling
@Slf4j
public class ThunderMoniInfoTask extends QuartzJobBean {
    @Autowired
    private ThunderMoniInfoMapper thunderMoniInfoMapper;
    @Autowired
    private ThunderMoniInfoService service;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //监控雷电信息
        List<ThunderMoniInfo> thunderMonitor = service.getThunderMonitor(1000);
        thunderMonitor.forEach(thunderMoniInfo -> {
            //当雷电的强度小于10时，说明被监控对象已经已经解除，将isremoved设置为true
            if (thunderMoniInfo.getStrength() < 10) {
                thunderMoniInfo.setIsremoved(true);
                service.updateThunderMonitor(thunderMoniInfo.getId().toString());
            } else {
                thunderMoniInfo.setIsremoved(false);
                service.updateThunderMonitor(thunderMoniInfo.getId().toString());
            }
        });
    }
}
